import java.util.Scanner;

/**
 * @Author 12629
 * @Date 2022/3/2 18:27
 * @Description：
 */
class Base{
    //不会提供默认的不带参数构造方法了
}

class Derived extends Base{

    public Derived(String s) {
        //super(s);
        //super();
        System.out.print("D");
    }
}


public class TestDemo {


    public static int firstUniqChar(String s) {
        int[] count = new int[26];// 0
        for(int i = 0; i<s.length();i++) {
            char ch = s.charAt(i);
            count[ch-'a']++;
        }

        for(int i = 0; i<s.length();i++) {
            char ch = s.charAt(i);
            if(count[ch-'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

    private static boolean isCharAndNumber(char ch) {
        if(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z') {
            return true;
        }
        return false;
    }


    public static boolean isPalindrome(String s) {
        if(s == null || s.equals("")) {
            return true;
        }

        s = s.toLowerCase();

        int left = 0;
        int right = s.length()-1;
        while(left < right) {


            while(left < right && !isCharAndNumber(s.charAt(left))) {
                left++;
            }

//            if(left == right) {
//                return true;
//            }

            while(left < right && !isCharAndNumber(s.charAt(right))) {
                right--;
            }

//            if(left == right) {
//                return true;
//            }

            if(s.charAt(left) != s.charAt(right)) {
                return false;
            }

            left++;
            right--;

        }
        return true;
    }

    public static void main(String[] args) {
        boolean ret = isPalindrome("abc ba");
        System.out.println(ret);
    }

    public static int func(String str) {
        if(str == null || str == "") {
            return 0;
        }
        int index = str.lastIndexOf(" ");
        int len = str.length()-index-1;
        return len;
    }

    public static void main11(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int ret = func(str);
            System.out.println(ret);
        }
    }

    public static void main9(String[] args) {
        StringBuilder sb1 = new StringBuilder("hello");
        String str = sb1.toString();

    }

    public static void main8(String[] args) {
        //String -> StringBuilder||StringBuffer
        String str = "abcd";

        StringBuilder sb1 = new StringBuilder(str);

        StringBuilder sb2 = new StringBuilder();
        sb2.append(str);

    }

    public static void main7(String[] args) {
        StringBuilder sb1 = new StringBuilder("abcd");
        sb1.append(1);
        sb1.append("hello").append("wobit");
        System.out.println(sb1);


        System.out.println("================");

        StringBuffer sb2 = new StringBuffer("abcd");
        sb2.append(1);
        sb2.append("hello").append("wobit");
        System.out.println(sb2);

        sb2.reverse();
        System.out.println(sb2);
    }

    public static void main6(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }


    public static void main5(String[] args) {
        String str = "abcd";

        StringBuilder sb = new StringBuilder();
        sb.append(str);//拼接

        for (int i = 0; i < 10; i++) {
            sb.append(i);
        }

        str = sb.toString();//匹配类型
        System.out.println(str);
    }

    public static void main4(String[] args) {

        String str = "abcd";
        for (int i = 0; i < 10; i++) {
            //str += i;
            StringBuilder sb = new StringBuilder();
            sb.append(str);//拼接
            sb.append(i);
            str = sb.toString();//匹配类型
        }
        System.out.println(str);
    }

    public static void main3(String[] args) {
        String s = "hello";
        //s = s+" world";
        StringBuilder sb = new StringBuilder();
        sb.append(s);//拼接
        sb.append("world");
        s = sb.toString();//匹配类型
        System.out.println(s);
    }

    public static void main2(String[] args) {
//        final int[] array = new int[10];
//        array[0] = 10;
//
//        array  = new int[20];
//
//        final int a = 10;
//        a = 20;
//
//        String str = new String("hello");

    }

    public static void func(int[] array) {
        array = new int[]{1,2,3,4};
    }

    public static void func2(int[] array) {
        array[0] = 10;
    }
    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";
    }

    public static void main1(String[] args) {
        String str = "ababcabcd";
        System.out.println(str.contains("abc"));
    }
}
